
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>StatelessWidget · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="section2.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="../chapter1/">
            
                <a href="../chapter1/">
            
                    
                    Flutter vs React Native
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2" data-path="../chapter2/">
            
                <a href="../chapter2/">
            
                    
                    环境配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.2.1" data-path="../chapter2/section1.html">
            
                <a href="../chapter2/section1.html">
            
                    
                    前置依赖环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2.2" data-path="../chapter2/section2.html">
            
                <a href="../chapter2/section2.html">
            
                    
                    配置 Android 环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2.3" data-path="../chapter2/section3.html">
            
                <a href="../chapter2/section3.html">
            
                    
                    配置 Flutter 环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2.4" data-path="../chapter2/section4.html">
            
                <a href="../chapter2/section4.html">
            
                    
                    创建并运行 Flutter 项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.3" data-path="../chapter3/">
            
                <a href="../chapter3/">
            
                    
                    核心Widget的使用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.3.1" data-path="../chapter3/section3.html">
            
                <a href="../chapter3/section3.html">
            
                    
                    MaterialApp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.2" data-path="../chapter3/section1.html">
            
                <a href="../chapter3/section1.html">
            
                    
                    Text
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.3" data-path="../chapter3/section2.html">
            
                <a href="../chapter3/section2.html">
            
                    
                    Center
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.4" data-path="../chapter3/section4.html">
            
                <a href="../chapter3/section4.html">
            
                    
                    Scaffold
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.5" data-path="../chapter3/section5.html">
            
                <a href="../chapter3/section5.html">
            
                    
                    常用的布局组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.6" data-path="../chapter3/section6.html">
            
                <a href="../chapter3/section6.html">
            
                    
                    AppBar
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.7" data-path="../chapter3/section7.html">
            
                <a href="../chapter3/section7.html">
            
                    
                    TabBar
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.8" data-path="../chapter3/section8.html">
            
                <a href="../chapter3/section8.html">
            
                    
                    TabController
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.9" data-path="../chapter3/section9.html">
            
                <a href="../chapter3/section9.html">
            
                    
                    TabBarView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.10" data-path="../chapter3/section10.html">
            
                <a href="../chapter3/section10.html">
            
                    
                    Drawer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.11" data-path="../chapter3/section11.html">
            
                <a href="../chapter3/section11.html">
            
                    
                    UserAccountsDrawerHeader
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.12" data-path="../chapter3/section12.html">
            
                <a href="../chapter3/section12.html">
            
                    
                    ListView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.13" data-path="../chapter3/section13.html">
            
                <a href="../chapter3/section13.html">
            
                    
                    CircleAvatar
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.4" data-path="./">
            
                <a href="./">
            
                    
                    自定义 Widget
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.1.4.1" data-path="section1.html">
            
                <a href="section1.html">
            
                    
                    StatelessWidget
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.4.2" data-path="section2.html">
            
                <a href="section2.html">
            
                    
                    StatefulWidget
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.5" data-path="../chapter5/">
            
                <a href="../chapter5/">
            
                    
                    事件绑定
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.6" data-path="../chapter6/">
            
                <a href="../chapter6/">
            
                    
                    dio 数据请求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.7" data-path="../chapter7/">
            
                <a href="../chapter7/">
            
                    
                    路由导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.8" data-path="../chapter8/">
            
                <a href="../chapter8/">
            
                    
                    修改 App 名称和图标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.9" data-path="../chapter9/">
            
                <a href="../chapter9/">
            
                    
                    打包发布 Android 项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.10" data-path="../chapter10/">
            
                <a href="../chapter10/">
            
                    
                    项目中用到的资源
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >StatelessWidget</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="statelesswidget">StatelessWidget</h1>
<p>StatelessWidget &#x662F;&#x65E0;&#x72B6;&#x6001;&#x63A7;&#x4EF6;&#xFF0C;&#x6CA1;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x79C1;&#x6709;&#x6570;&#x636E;&#xFF0C;&#x662F;&#x7EAF;&#x5C55;&#x793A;&#x578B;&#x7684;&#x63A7;&#x4EF6;&#xFF0C;&#x57FA;&#x672C;&#x5B9A;&#x4E49;&#x8FC7;&#x7A0B;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyMidget</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  <span class="hljs-comment">// &#x6784;&#x9020;&#x51FD;&#x6570;&#xFF1A;</span>
  <span class="hljs-comment">// &#x5176;&#x4E2D;&#x7684; this.title &#x5B9A;&#x4E49;&#x7684;&#x662F;&#x547D;&#x540D;&#x53C2;&#x6570;</span>
  <span class="hljs-comment">// @required &#x7528;&#x6765;&#x89C4;&#x5B9A;&#x67D0;&#x4E2A;&#x6570;&#x636E;&#x5728;&#x521D;&#x59CB;&#x5316;&#x7684;&#x65F6;&#x5019;&#x662F;&#x5FC5;&#x987B;&#x8981;&#x63D0;&#x4F9B;&#x7684;&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x62A5;&#x9519;&#x3002;</span>
  MyApp({Key key, <span class="hljs-meta">@required</span> <span class="hljs-keyword">this</span>.title}) : <span class="hljs-keyword">super</span>(key: key);

  <span class="hljs-comment">// final&#xFF1A;&#x7528;&#x4E8E;&#x4FEE;&#x9970;&#x53D8;&#x91CF;&#xFF0C;&#x8868;&#x793A;&#x5355;&#x8D4B;&#x503C;&#xFF08;single-assignment&#xFF09;&#xFF0C;</span>
  <span class="hljs-comment">// &#x4F7F;&#x7528;final&#x4FEE;&#x9970;&#x7684;&#x53D8;&#x91CF;&#x5FC5;&#x987B;&#x8FDB;&#x884C;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x4E00;&#x65E6;&#x88AB;&#x8D4B;&#x503C;&#x4E4B;&#x540E;&#xFF0C;&#x4E0D;&#x80FD;&#x591F;&#x518D;&#x6B21;&#x88AB;&#x8D4B;&#x503C;,&#x5426;&#x5219;&#x7F16;&#x8BD1;&#x4F1A;&#x62A5;&#x9519;&#x3002;</span>
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">String</span> title;

  <span class="hljs-comment">// build &#x51FD;&#x6570;&#x76F8;&#x5F53;&#x4E8E; react.js &#x4E2D;&#x7684; render &#x51FD;&#x6570;</span>
  <span class="hljs-comment">// &#x5FC5;&#x987B; return &#x4E00;&#x4E2A; UI &#x7ED3;&#x6784;&#xFF0C;&#x7528;&#x6765;&#x6784;&#x5EFA;&#x5F53;&#x524D;&#x63A7;&#x4EF6;&#x5BF9;&#x5E94;&#x7684;UI&#x754C;&#x9762;</span>
  <span class="hljs-comment">// &#x5728; StatelessWidget &#x63A7;&#x4EF6;&#x4E2D;&#xFF0C;build &#x51FD;&#x6570;&#x662F;&#x5FC5;&#x987B;&#x7684;</span>
  <span class="hljs-meta">@override</span>
  Widget build(BuildContext context) {
    <span class="hljs-keyword">return</span> Text(title);
  }
}
</code></pre>
<p>&#x57FA;&#x672C;&#x4F7F;&#x7528;&#x8FC7;&#x7A0B;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-dart"><span class="hljs-keyword">void</span> main() =&gt; runApp(
  <span class="hljs-comment">// MyApp() &#x51FD;&#x6570;&#x7684;&#x8C03;&#x7528;&#xFF0C;&#x662F; new MyApp() &#x7684;&#x7B80;&#x5199;&#x5F62;&#x5F0F;&#xFF0C;</span>
  <span class="hljs-comment">// &#x5176;&#x4E2D; title &#x662F;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#xFF0C;</span>
  <span class="hljs-comment">// &#x4E14;&#x5FC5;&#x987B;&#x4F20;&#x9012; title &#x6570;&#x636E;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5DF2;&#x88AB;&#x6807;&#x8BB0;&#x4E3A; @required &#x5FC5;&#x586B;&#x9879;</span>
  MyApp(title: <span class="hljs-string">&apos;Flutter&#x521D;&#x4F53;&#x9A8C;&#x9E2D;&apos;</span>)
);
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: 自定义 Widget">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="section2.html" class="navigation navigation-next " aria-label="Next page: StatefulWidget">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"StatelessWidget","level":"1.1.4.1","depth":3,"next":{"title":"StatefulWidget","level":"1.1.4.2","depth":3,"path":"chapter4/section2.md","ref":"chapter4/section2.md","articles":[]},"previous":{"title":"自定义 Widget","level":"1.1.4","depth":2,"path":"chapter4/README.md","ref":"chapter4/README.md","articles":[{"title":"StatelessWidget","level":"1.1.4.1","depth":3,"path":"chapter4/section1.md","ref":"chapter4/section1.md","articles":[]},{"title":"StatefulWidget","level":"1.1.4.2","depth":3,"path":"chapter4/section2.md","ref":"chapter4/section2.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter4/section1.md","mtime":"2018-12-14T05:32:09.913Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-12-17T10:25:33.898Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

